// pages/look_my/look_my.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    companyList: [],
    companyDateList: [],
    companyDateMapList: {},
    companyListMore: {page:1},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.fetchCompany();
  },

  fetchCompany() {
    util.fetch(this, 'xilujob.company/look_my', {}, 'companyListMore', 'companyList', 'data', list=>{
      list.forEach(company=>{
        let viewDate = util.formatDatetime(company.view_time,'yyyy年m月d日');
        if(this.data.companyDateList.indexOf(viewDate)===-1) {
          this.data.companyDateList.push(viewDate);
        }
        let companyList = this.data.companyDateMapList[viewDate] || [];
        companyList.push(company);
        this.setData({
          companyDateList: this.data.companyDateList,
          ['companyDateMapList.'+viewDate]: companyList
        });
      });
      return [];
    });
  },

});
